<?php

class ChongzhiModel extends Model {
	
	public function get_all_list($where,$order,$limit,$if_count=false){
		if($if_count){
	   $sql = "select count(cz.id) as total from ".$this->prefix."member_chongzhi cz"."
			 left join ".$this->prefix."member m on cz.member_id=m.id"."
			 where $where";
			 $res = $this->db->query($sql)->row_array();
			 return $res['total'];
	   }
		 $sql = "select cz.*,m.name,m.id as mid from ".$this->prefix."member_chongzhi cz"."
			 left join ".$this->prefix."member m on cz.member_id=m.id"."
			 where $where order by $order limit $limit";
			//return $sql;
		$res = $this->db->query($sql)->result_array();
		return $res;
	}
	
	public function get_chongzhi_zonge($where){
		$sql = "select sum(cz.jine) as z from ".$this->prefix."member_chongzhi cz "."
		left join ".$this->prefix."member m on m.id=cz.member_id where $where";
		$res = $this->db->query($sql)->row_array();
		return $res['z'];
	}
	
	
	public function get_chonghzi_time($time){
		$sql = "select id from ".$this->prefix."member_chongzhi where addtime=$time";
		$res = $this->db->query($sql)->row_array();
		return $res['id'];
	}
	
	public function get_one_list($id){
		$sql = "select c.*,m.id as m_id,m.name as m_name,m.openid as m_openid from ".$this->prefix."member_chongzhi c"."
		left join ".$this->prefix."member m on c.member_id=m.id where c.id=$id";
		return $this->db->query($sql)->row_array();
	}
	
	
	public function get_jinm_one($id){
		$sql = "select id,member_id,jine,paystatus from ".$this->prefix."member_chongzhi where id=$id";
		return $this->db->query($sql)->row_array();
	}
	
	public function get_xml_one($sn){
		$sql = "select id,member_id,jine,paystatus from ".$this->prefix."member_chongzhi where sn='".$sn."'";
		return $this->db->query($sql)->row_array();
	}
	
	
	
}